class Bus {
    constructor() {
        this.cb = {};
    }

    $on(name, fn) {
        if (!this.cb[name]) {
            this.cb[name] = [];
        }
        this.cb[name].push(fn);
    }

    $emit(name, args) {
        if (!this.cb[name]) {
            throw new Error(`${name} is unavailable`);
        }
        this.cb[name].forEach((fn) => fn.call(args));
    }
}
